package com.example.springboot.controller;

import com.example.springboot.entity.User;
import com.example.springboot.mapper.LoginMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
@Autowired
    private LoginMapper loginMapper;
@GetMapping
public Map<String,Object> index(@RequestParam String username,@RequestParam String password){
    Map<String,Object> res=new HashMap<>();
    List<User> data=loginMapper.selectall(username,password);
   if(data.isEmpty()){
       res.put("code",500);

       res.put("msg","用户名或密码错误");

   }else{
       res.put("code",200);
res.put("data",data);
       res.put("msg","登录成功");

   }
    return res;
//    return loginMapper.selectall(username,password);
}

}
